<%
layout("/layouts/platform.html"){
%>
     <header class="header navbar bg-white shadow">
		<div class="btn-group tool-button" style="padding:8px 0">
			<table>
           		<tbody>
           			<tr>
                  		<td>
                       		<input type="text" id="title" name="title" onclick="this.value=''" class="form-control" placeholder="卡券名" autofocus>
                        </td>
                        <td style="padding-left: 5px;">
                            <button id="searchBtn" type="button" class="btn btn-default"><i class="fa fa-search"></i>&nbsp;查询</button>
                      	</td>
                        </tr>
                    </tbody>
            </table>
		</div>
	    <div class="pull-right offscreen-right">
	         <a class="btn btn-default navbar-btn" href="${base}/platform/wx/card/add" ><i class="fa fa-plus"></i>&nbsp;新增</a>
		</div>
	</header>
    <div class="panel-body" style="padding-top: 70px;">
		<div class="box">
			<div class="box-body">
				<div class="col-sm-12">
					<div class="row">
				        <table class="table table-bordered table-hover mg-t datatable">
			                <thead>
			                <tr>
			                	<th>卡券名称</th>
			                    <th>卡券类型</th>
			                    <th>额度</th>
			                    <th>card_id</th>
			                    <th>操作</th>
              			</table>
	    			</div>
				</div>
			</div>
		</div>
	</div>
<script language="JavaScript">
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">frtip',
            "searching":false,
            "processing": true,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/plugins/datatables/cn.json"
            },
            "preDrawCallback": function () {
                sublime.showLoadingbar($(".main-content"));
            },
            "drawCallback": function () {
                sublime.closeLoadingbar($(".main-content"));
            },
            "ajax": {
                "url": "${base}/platform/wx/card/data",
                "type": "post",
                "data": function (d) {
                    d.title = $('#title').val();
                }
            },
            "order": [[0, "desc"]],
            "columns": [
                {"data": "title", "bSortable": true},
                {"data": "card_type", "bSortable": true},
                {"data": "card_fee", "bSortable": true},
                {"data": "card_id", "bSortable": true}
            ],
            "columnDefs": [
                {
                    "render": function (data, type, row) {
                        return 	'<div >'+
                        '<a class="btn btn-xs btn btn-default " href="${base}/platform/wx/card/detail/' + row.id + '" data-pjax><i class="fa fa-edit"></i>&nbsp;修改</a> ' +
                        '</div>';
                    },
                    "targets": 4
                }
                ,
                {
                    "render": function (data, type, row) {
                    	if(data=="GROUPON"){
                    		return "团购券";
                    	}else if(data=="CASH"){
                    		return "代金券";
                    	}else if(data="DISCOUNT"){
                    		return "折扣券";
                    	}else if(data="GIFT"){
                    		return "兑换券";
                    	}else if(data="GENERAL_COUPON"){
                    		return "优惠券";
                    	}
                    },
                    "targets": 1
                }
            ]
        });
        $("#searchBtn").on('click', function () {
            datatable.ajax.reload();
        });
    }
    $(document).ready(function () {
        initDatatable();
    });
</script>
<%}%>
